package com.itheima.controller.backend.security;

import com.itheima.common.entity.Result2;
import com.itheima.pojo.dto.OrderSettingDto;
import com.itheima.pojo.vo.OrderSettingVO;
import com.itheima.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * 预约设置
 */
@RestController
@RequestMapping("/ordersetting")
@Slf4j
public class OrderSettingController {

    @Autowired
    private OrderSettingService orderSettingService;


    /**
     * 下载预约设置数据
     * @param response
     * @param filename
     */
    @GetMapping("/download")
    public void download(HttpServletResponse response ,String filename) throws IOException {
        log.info("开始下载");
        orderSettingService.download(response,filename);
    }

    /**
     * 查询预约设置数据
     * @param
     * @return
     */
    @GetMapping("/getOrderSettingByMonth")
    public Result2 getOrderSettingByMonth(String month) {
        log.info("开始查询预约设置数据"+ month);


        List<OrderSettingVO>  list =orderSettingService.getOrderSettingByMonth(month);
        return new Result2(true,"查询成功",list);
    }
    /**
     * 根据日期修改预约设置数据
     * @param
     * @return
     */
    @PostMapping("/editNumberByOrderDate")
    public Result2 editNumberByOrderDate( @RequestBody OrderSettingDto orderSetting) {
        log.info("开始修改预约设置数据"+ orderSetting);
        orderSettingService.editNumberByOrderDate(orderSetting);
        return new Result2(true,"修改成功");
    }
    /**
     * 上传文件
     */
    @PostMapping("/upload")
    public Result2 upload(MultipartFile excelFile) {
        log.info("开始上传文件");
        orderSettingService.upload(excelFile);
        return new Result2(true,"上传成功");
    }
}
